package com.laiyizhan.cms.first.controller;


import com.laiyizhan.cms.first.request.FifthRequest;
import com.laiyizhan.cms.first.service.impl.FifthServiceImpl;
import com.laiyizhan.cms.manager.request.AdminUserRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.jws.WebParam;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * Created by SoulWolf on 2017/7/15.
 */
@Controller
@RequestMapping("/admin")
public class FifthController {

    @Autowired
    FifthServiceImpl fifthService;

    /*目录页面*/
    @RequestMapping(value = "/fifth/index/show")
    public String Fifth_index(FifthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        httpSession.setAttribute("number", 1);
        modelMap.put("state",fifthService.Fifth_index(request));
        return "/fifth/index";
    }



    /*一个用于返回页面，一个用于提交页面*/
    @RequestMapping(value = "/fifth/a/show")
    public String fifth_a(FifthRequest request) {
        return "/fifth/main";
    }
    @RequestMapping(value = "/fifth/a")
    public String Fifth_a_record(FifthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        String result = fifthService.Fifth_a(request);
        modelMap.put("state",fifthService.Fifth_index(request));
        if(result=="no"){
            modelMap.put("error","当职称人数不为0的时候，该职称的在职工年人均工资也不能为0");
            modelMap.put("link","/admin/fifth/a/show");
            return "/error/error";
        }
        return "/fifth/index";
    }

    @RequestMapping(value = "/fifth/b/show")
    public String Fifth_b() {
        return "/fifth/b";
    }
    @RequestMapping(value = "/fifth/b")
    public String Fifth_b_record(FifthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        fifthService.Fifth_b(request);
        modelMap.put("state",fifthService.Fifth_index(request));
        return "/fifth/index";
    }

    @RequestMapping(value = "/fifth/c/show")
    public String Fifth_c() {
        return "/fifth/c";
    }
    @RequestMapping(value = "/fifth/c")
    public String Fifth_c_record(FifthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        fifthService.Fifth_c(request);
        modelMap.put("state",fifthService.Fifth_index(request));
        int order = (int)httpSession.getAttribute("number");
        if(order<5){
            httpSession.setAttribute("number",order+1);
        }else{
            return "fifth/index";
        }
        return "/fifth/c";
    }

    @RequestMapping(value = "/fifth/d/show")
    public String Fifth_d(FifthRequest request) {
        return "/fifth/d";
    }
    @RequestMapping(value = "/fifth/d")
    public String Fifth_d_record(FifthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        fifthService.Fifth_d(request);
        modelMap.put("state",fifthService.Fifth_index(request));
        return "/fifth/index";
    }

    @RequestMapping(value = "/fifth/e/show")
    public String Fifth_e() {
        return "/fifth/e";
    }
    @RequestMapping(value = "/fifth/e")
    public String Fifth_e_record(FifthRequest request, HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        fifthService.Fifth_e(request);
        modelMap.put("state",fifthService.Fifth_index(request));
        return "/fifth/index";
    }







}
